<template>
  <!--项目计划信息  -->
  <div>
    <FormPanel
      ref="formPanel"
      :list="initForm"
      :cols="1"
      :formType="value.type"
      :labelWidth="120"
      :isSubmitBtn="false"
      @formChange="formChangeHandle"
    />
  </div>
</template>

<script>
import { dictionary } from '@/utils/dictMixin';
import { selectListByBill } from '@/api/cms-api/projectOperating/plan/index';
export default {
  mixins: [dictionary],
  props: {
    value: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      initForm: this.initFormFun(),
      formValue: {},
      fileRes: {},
      fileRes1: {},
      fileRes2: {},
      fileRes3: {},
      fileRes4: {},
      fileRes5: {}
    };
  },
  mounted() {
    // console.log(this.value); //获取到行id 、类型（新增、详情）
    //请求接口进行赋值，自己写吧
  },
  methods: {
    async file() {
      //现场高清照片
      this.fileRes = await selectListByBill({ planId: this.planId, billType: 25791001 });
      if (this.fileRes.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes.data.length; j++) {
          let o1 = { name: this.fileRes.data[j].fileName };
          let o2 = { url: this.fileRes.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'photoUrl').initialValue = caseUrlList;
      }
      //项目核销材料
      this.fileRes1 = await selectListByBill({ planId: this.planId, billType: 25791002 });
      if (this.fileRes1.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes1.data.length; j++) {
          let o1 = { name: this.fileRes1.data[j].fileName };
          let o2 = { url: this.fileRes1.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'cancellationUrl').initialValue = caseUrlList;
      }
      //实际使用费用明细
      this.fileRes2 = await selectListByBill({ planId: this.planId, billType: 25791003 });
      if (this.fileRes2.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes2.data.length; j++) {
          let o1 = { name: this.fileRes2.data[j].fileName };
          let o2 = { url: this.fileRes2.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'feeDetailUrl').initialValue = caseUrlList;
      }
      //合同报价单
      this.fileRes3 = await selectListByBill({ planId: this.planId, billType: 25791004 });
      if (this.fileRes3.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes3.data.length; j++) {
          let o1 = { name: this.fileRes3.data[j].fileName };
          let o2 = { url: this.fileRes3.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'contractOfferUrl').initialValue = caseUrlList;
      }
      //发票
      this.fileRes4 = await selectListByBill({ planId: this.planId, billType: 25791005 });
      if (this.fileRes4.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes4.data.length; j++) {
          let o1 = { name: this.fileRes4.data[j].fileName };
          let o2 = { url: this.fileRes4.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'billUrl').initialValue = caseUrlList;
      }
      //其它
      this.fileRes5 = await selectListByBill({ planId: this.planId, billType: 25791007 });
      if (this.fileRes5.data.length > 0) {
        let caseUrlList = [];
        for (let j = 0; j < this.fileRes5.data.length; j++) {
          let o1 = { name: this.fileRes5.data[j].fileName };
          let o2 = { url: this.fileRes5.data[j].fileId };
          let a = Object.assign(o1, o2);
          caseUrlList.push(a);
        }
        this.initForm.find(item => item.fieldName === 'otherUrl').initialValue = caseUrlList;
      }
    },
    init() {
      if (this.value.type === 'show') {
        //项目计划总结ID
        this.planId = this.value.row.planId;
        //查询附件
        this.file();
        this.initForm.forEach(x => {
          x.initialValue = this.value.row[x.fieldName];
        });
      }
    },
    //搜索数据
    initFormFun() {
      return [
          {
          type: 'UPLOAD_FILE',
          label: '现场高清照片',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'photoUrl',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
        },
        {
          type: 'UPLOAD_FILE',
          label: '项目核销材料',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'cancellationUrl',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
        },
        {
          type: 'UPLOAD_FILE',
          label: '实际使用费用明细',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'feeDetailUrl',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
        },
        {
          type: 'UPLOAD_FILE',
          label: '合同报价单',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'contractOfferUrl',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
          // rules: [{ required: true, message: '请上传合同报价单', trigger: 'blur' }]
        },
        {
          type: 'UPLOAD_FILE',
          label: '发票',
          disabled: this.type === 'show' ? true : false,
          fieldName: 'billUrl',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload'
          }
          // rules: [{ required: true, message: '请上传发票', trigger: 'blur' }]
        },
        {
          type: 'UPLOAD_FILE',
          label: '其它',
          fieldName: 'otherUrl',
          initialValue: '',
          upload: {
            actionUrl: '/api/file/oss/upload',
            limit: 99
          }
        }
      ];
    },
    formChangeHandle(val) {
      this.formValue = val;
    }
  },
  mounted() {
    this.init();
  }
};
</script>
